﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.IO;
using System.Net;
namespace HGZP.PLL
{
    /// <summary>
    /// 功能：生成静态页
    /// 作者：许金杰
    /// 时间：2011.7.2
    /// </summary>
    public class staticpage
    {
        /// <summary>
        ///生成静态页
        /// </summary>
        /// <param name="Url">要生成静态页的网址</param>
        /// <param name="mypath">静态页保存路径</param>
        /// <returns></returns>
        public static string getUrltoHtml(string Url, string mypath)
        {
            string returnhtml = "";
            string errorMsg = "";
            try
            {
                System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
                // Get the response instance. 
                System.Net.WebResponse wResp = wReq.GetResponse();
                // Read an HTTP-specific property 
                //if (wResp.GetType() ==HttpWebResponse) 
                //{ 
                //DateTime updated =((System.Net.HttpWebResponse)wResp).LastModified; 
                //} 
                // Get the response stream. 
                System.IO.Stream respStream = wResp.GetResponseStream();
                // Dim reader As StreamReader = New StreamReader(respStream) 
                System.IO.StreamReader reader = new System.IO.StreamReader(respStream);
                ///////替换掉不需要的字符串
                returnhtml = reader.ReadToEnd();
                int sta = returnhtml.IndexOf("<form");
                int end = returnhtml.IndexOf("<div");
                returnhtml = returnhtml.Substring(0, sta) + returnhtml.Substring(end, returnhtml.Length - end);
                returnhtml = returnhtml.Replace("</form>", "");
                ///////////
                StreamWriter writerstring = File.CreateText(mypath);
                writerstring.Write(returnhtml);
                writerstring.Close();
                return returnhtml;
            }
            catch (System.Exception ex)
            {
                errorMsg = ex.Message;
            }
            return "";
        }
    }
}
